/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package main.testers;

import datatypes.Antenna;

import java.io.File;
import java.util.List;
import modules.legislation.LegislationAdapter;
import modules.legislation.PathlossInterface;
import modules.legislation.law.Belgium;
import modules.legislation.law.LawInterface;
import modules.pathloss.CoverageAdapter;
import modules.pathloss.PathLossAdapter;
import tools.gis.antennaReader.AntennaSite;
import tools.gis.antennaReader.AntennaSiteReader;
import tools.math.MathTools;
import tools.settings.SettingsAdapter;
import tools.settings.SettingsMissingException;

/**
 *
 * @author Pieter Backaert
 */
public class SarValueTester {



    public static void main(String[] args) throws SettingsMissingException{
        CoverageAdapter ca = CoverageAdapter.getInstance();
        SettingsAdapter sa = SettingsAdapter.getInstance();


        PathlossInterface instanceOfPathlossInterface = PathLossAdapter.getInstance();
        LawInterface law = new Belgium(instanceOfPathlossInterface);

        LegislationAdapter la = new LegislationAdapter(law , ca);

        try {

	        sa.setDefaultFolder(new File("C:\\Documents and Settings\\Pieter\\Mijn documenten\\_NETBEANS Projecten\\NMO-coverage_wireless_networks\\src"));
	        //sa.setDefaultFolder(new File("D:\\Documenten\\UGent\\NMO\\Coverage_for_wireless_networks\\src"));
	        //sa.setDefaultFolder(new File("C:\\Eclipse Env\\CWN\\src"));

            sa.addSettings(new File(sa.getDefault_folder(), "gsm.xml"));

            AntennaSiteReader areader = new AntennaSiteReader();
            List<AntennaSite> list = areader.getAntennaSiteList(new File("C:\\Bipt antennes Brussels hoofdstedelijk gewest v2.shp"));
            Antenna[] antennas = areader.filterSiteListGUI(list);

//            for (int i = 0; i < antennas.length; i++) {
//                Antenna a = antennas[i];
//                double radius = ca.getRangeRadius(a);
//                //System.out.println("Antenna " + i + "  " + a.toString() + "  has radius " + radius);
//            }

            Antenna a = antennas[0];
//           a=  antennas[2];
//            System.out.println("*******************************************************************");
//            System.out.println( a.toString() );
//            System.out.println("met max.power van " +  la.getMaximumAntennaPower(a) );
//            for(double i=0 ; i<2000 ; i+=10) {
//                double result = instanceOfPathlossInterface.getDbAtDistance(a, i);
//                System.out.println("result van de pathlos voor " + i + " = " + result);
//            }

            a =  antennas[12];
            System.out.println("*******************************************************************");
            System.out.println( a.toString() );
            System.out.println("met max.power van " +  la.getMaximumAntennaPower(a) );
            for(double i=0 ; i<2000 ; i+=5) {
                double pl = instanceOfPathlossInterface.getDbPathLoss(a, i);

                double EIRP = a.getPower() + a.getGain();

                double E1 = MathTools.calculate_E_from_PathLoss(EIRP, pl, a.getFrequency() );
                double result1 = MathTools.microVperM2VperM(E1);

                double E2 = MathTools.calculate_simple_E_from_PathLoss(EIRP, pl, a.getFrequency() );


                System.out.println("pathloss=" + pl + " EIRP=" + EIRP + "    ******** E1="  + result1 + "    ******** E2="  + E2  );

                //double result2 = MathTools.dBm2mWatt(result);
                //double result3 = MathTools.dBm2Watt(result);
                //double result4 = MathTools.calculateEfieldAdvanced(result3 , i);
                //System.out.println("result van de pathlos voor " + i + " = " + result  + "***** in Watt="  +result3 + " ***** in E [microV/m]="+ result4);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
